home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C18 / NumberPhotos.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  905 b   |  34 lines

  1. //: C18:NumberPhotos.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Find the marker "XXX" and replace it with an
  7. // incrementing number whereever it appears. Used
  8. // to help format a web page with photos in it
  9. #include "../require.h"
  10. #include <fstream>
  11. #include <sstream>
  12. #include <iomanip>
  13. #include <string>
  14. using namespace std;
  15.  
  16. int main(int argc, char* argv[]) {
  17.   requireArgs(argc, 2);
  18.   ifstream in(argv[1]);
  19.   assure(in, argv[1]);
  20.   ofstream out(argv[2]);
  21.   assure(out, argv[2]);
  22.   string line;
  23.   int counter = 1;
  24.   while(getline(in, line)) {
  25.     int xxx = line.find("XXX");
  26.     if(xxx != string::npos) {
  27.       ostringstream cntr;
  28.       cntr << setfill('0') << setw(3) << counter++;
  29.       line.replace(xxx, 3, cntr.str());
  30.     }
  31.     out << line << endl;
  32.   }
  33. } ///:~
  34.